package com.yuke.cloud.service.smc.config;


import com.yuke.cloud.service.smc.entity.DmsSend;
import com.yuke.cloud.service.smc.service.DmsSendService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@Component
public class KeyExpiredListener implements MessageListener {
    @Resource
    private DmsSendService dmsSendService;
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        System.err.println("redis key有过期的" + message);
        if(message.toString().contains("SendJob")){
            //司机转单检查
            String[] split = message.toString().split(":");
            String s1 = split[1];
            Long sendId = Long.valueOf(s1);
            //todo
            DmsSend dmsSend = dmsSendService.findById(sendId);
            //如果订单还是转出状态
            if (dmsSend != null && dmsSend.getSendStatus().equals((byte)4)){
                dmsSend.setSendStatus((byte)1);
                dmsSend.setUpdateTime(new Date());
                dmsSendService.update(dmsSend);
            }
        }
    }
}
